package tianwang.service.stat;

import java.util.ArrayList;
import java.util.List;

import tianwang.model.AticleModel;
import tianwang.services.collect.CollectResult;
import tianwang.services.collect.Collecter;

public class ArticleStat {
	/*
	 * 文章模型
	 * 需要注入
	 */
	private AticleModel aticleModel = null;
	
	private List<Collecter<CollectResult>> collecters = null;
	
	private List<CollectResult> collecterReuslts = null;
	public void setAticleModel(AticleModel model){
		this.aticleModel = model;
	}
	
	public void setCollecters(List<Collecter<CollectResult>> collecters) {
		this.collecters = collecters;
	}
	
	public List<CollectResult> getResult(){
		return this.collecterReuslts;
	}
	
	public void doCollect() throws Exception{
		this.collecterReuslts = new ArrayList<CollectResult>();
		Collecter<CollectResult> coll = null;
		for(int i = 0, len = collecters.size(); i < len; i++){
			coll = this.collecters.get(i);
			CollectResult reslt = coll.collect(this.aticleModel);
			if(reslt == null){
				this.collecterReuslts.add(null);
			}else{
				this.collecterReuslts.add(reslt);
			}
			
		}
	}
	
	public int size(){
		return this.collecters == null?0:this.collecters.size();
	}
}
